<?php
    $num = 10.4567;

    // php保留两位小数并且四舍五入
    // 第一种：利用round()对浮点数进行四舍五入
    $result = round($num, 2);
    echo $result; //10.46
    echo "<hr />";

    // 第二种：利用sprintf格式化字符串
    $result = sprintf("%.2f", $num);
    echo $result; //10.46
    echo "<hr />";
    
    // 第三种：利用千位分组来格式化数字的函数number_format()
    $result = number_format($num, 2);
    echo $result; //10.46
    echo "<hr />";
    //或者如下
    $result = number_format($num, 2, '.', '');
    echo $result; //10.46
    echo "<hr />";

    // php保留两位小数并且不四舍五入
    $result = sprintf("%.2f", substr(sprintf("%.3f", $num), 0, -1));
    echo $result;
    echo "<hr />";

    // php进一法取整
    $result = ceil($num);//11
    echo $result;
    echo "<hr />";

    // php舍去法取整
    $result = floor($num);//10
    echo $result;
